home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / source / fft.old < prev    next >
Encoding:
Text File  |  1991-08-10  |  4.5 KB  |  203 lines

  1.     page    132,63,1,1
  2.     opt    rc
  3.     title    'FFT transform and periodogram calculation'
  4.  
  5. ;***************************************************************
  6. ;* FFT.ASM -- FFT transform, periodogram calculation and       *
  7. ;*          main control loop                    *
  8. ;*                                   *
  9. ;* Provides main control loop of the FFT based periodogram     *
  10. ;* spectrum analyzer.                           *
  11. ;*                                   *
  12. ;* Periodogram calculation is based on the book:           *
  13. ;*    Oppenheim, A, Shafer, R.:                   *
  14. ;*    "Digital Signal Processing",                   *
  15. ;*    Prentice-Hall, 1975                       *
  16. ;*                                   *
  17. ;* This module uses registers as follows:               *
  18. ;*  r0 -                               *
  19. ;*  r1 -                               *
  20. ;*  r4 -                               *
  21. ;*  r5 -                               *
  22. ;*  r6 -                               *
  23. ;*                                   *
  24. ;* Copyright (C) 1991 by Alef Null. All rights reserved.       *
  25. ;* Author(s): Jarkko Vuori, OH2LNS                   *
  26. ;* Modification(s):                           *
  27. ;***************************************************************
  28.  
  29.     nolist
  30.     include 'ioequlc'
  31.     list
  32.  
  33.     section FFT
  34.     xdef    ssi_ini,fft_i
  35.     xdef    m_loop
  36.     xref    m_cra,m_crb,m_tde,m_sr,m_tx
  37.  
  38.     org    p:
  39.  
  40.     nolist
  41.     include 'macros'
  42.     include 'fftr2a'
  43.     list
  44.  
  45. points    equ    1024
  46.  
  47. ; multiply p:(r0) (data) by p:(r1) (window) and
  48. ; put the result to x/y:(r2) (destination)
  49. winblk    macro    dest
  50.     move            p:(r0)+,x0
  51.     move            p:(r1)+,x1
  52.     mpyr    x0,x1,a
  53.     do    #points-1,_endloop
  54.     move            p:(r0)+,x0
  55.     move            p:(r1)+,x1
  56.     mpyr    x0,x1,a     a,dest:(r2)+
  57. _endloop
  58.     move            a,dest:(r2)+
  59.     endm
  60.  
  61.  
  62. ;****************************
  63. ;*    SSI initialization    *
  64. ;****************************
  65. ssi_ini
  66. ; initialize SSI,
  67.     IF    !DEBUG
  68.     movep            #$4000,x:m_cra        ; 16 bit word
  69.     movep            #$f200,x:m_crb        ; syncronous,word frame,ext clk
  70.     ELSE
  71.     movep            #$4011,x:m_cra        ; 16 bit word, abt. 19.2 ksamples/s
  72.     movep            #$f620,x:m_crb        ; syncronous,word frame,ext clk
  73.     ENDIF
  74.  
  75.     rts
  76.  
  77.  
  78. ;****************************
  79. ;*      ADC & FFT        *
  80. ;*    initialization        *
  81. ;****************************
  82. fft_i
  83. ; program the A/D & D/A converter chip (TLC32044, master clock is 5.184MHz)
  84. ; disable A/D high-pass filter, disable loopback, disable AUX IN,
  85. ; select syncronous mode, select input span 3Vpp, insert sinx/x correction
  86. ; lowpass cutoff frequency at    3600Hz -> TA  =  9 (SCF = 288kHz)
  87. ; sampling frequency is     8000Hz -> TB  = 36
  88. ; unit sampling correction time  0.4uS -> TA' =  2
  89.     pgmtlc    %10101001,9,2,36
  90.  
  91. ; initialize input sample pointers
  92.     move            #samples,r7
  93.     move            #points-1,m7
  94.  
  95. ; and FFT average counter
  96.     move            p:NN2,a
  97.     move            a,y:<count
  98.     rts
  99.  
  100.  
  101. ;****************************
  102. ;*      Main Loop        *
  103. ;****************************
  104. loop    wait
  105. m_loop
  106.  
  107. ; check if one block converted
  108.     move            #>samples,x0
  109.     move    r7,a
  110.     cmp    x0,a        x0,r0
  111.     jne    <loop
  112.  
  113. ; yes, multiply samples with window
  114.     move            #window,r1
  115.     move            #data,r2
  116.     move            #-1,m1
  117.     move            m1,m2
  118.  
  119.     bchg    #blksel,x:<status
  120.     jcc    <fft1
  121.     winblk    x
  122.     jmp    <loop
  123. fft1    winblk    y
  124.  
  125. ; real and imaginary banks filled, so transform data
  126. ; 129000 cycles, 6.22 mS
  127.     fftr2a    points,data,coef
  128.  
  129. ; extract, scale and accumulate data
  130. ; select accumulator
  131.     move            #accb,r0
  132.     jset    #accsel,x:<status,fft2
  133.     move            #acca,r0
  134. fft2
  135.  
  136. ; extract and take square
  137. ;   1/4[(Zr(k)+Zr(N-k))^2 + (Zi(k)-Zi(N-k))^2 + Zi(N-k)+Zi(k))^2 + Zr(N-k)-Zr(k))^2]
  138. ; = 1/2[Zr(k)^2 + Zi(k)^2 + Zr(N-k)^2 + Zi(N-k)^2]
  139.     move            #data,r1
  140.     move            #data+points-1,r2
  141.     move            #points/2,n1
  142.     move            n1,n2
  143.     move            #0,m1
  144.     move            m1,m2
  145.  
  146.     move            x:(r1),x0
  147.     do    #points/2,endcopy            ; k = 0..N/2
  148.     mpy    x0,x0,a     y:(r1)+n1,y0        ; Zr(k)^2 + Zi(k)^2
  149.     mac    y0,y0,a     x:(r2),x0            ; Zr(N-k)^2 + Zi(N-k)^2
  150.     mac    x0,x0,a     y:(r2)-n2,y0
  151.     macr    y0,y0,a     #@pow(2,-11-4),x0
  152.     move    a,x1
  153.     mpy    x0,x1,a
  154.     move            p:(r0),x0            ; add to result
  155.     add    x0,a
  156.     rnd    a        x:(r1),x0
  157.     move            a,p:(r0)+
  158. endcopy
  159.  
  160. ; check if enought integrated
  161.     move            y:<count,a
  162.     move            #>1,x0
  163.     sub    x0,a        #>accb,x0
  164.     move            a,y:<count
  165.     jne    <loop
  166.  
  167. ; yes, send result to host
  168.     move            p:NN2,a
  169.     move            a,y:<count
  170.  
  171.     jset    #accsel,x:<status,fft4
  172.     move            #>acca,x0
  173. fft4    move            #>points/2,a
  174.     add    x0,a
  175.     move    a,x1
  176.  
  177.     bchg    #$2,x:m_pcd
  178.     jsr    <putblk
  179.  
  180. ; change to new accumulator, and clear it
  181.     clr    a        #acca,r0
  182.     bchg    #accsel,x:<status
  183.     jcs    <fft5
  184.     move            #accb,r0
  185. fft5    do    #points/2,_endloop
  186.     move            a,p:(r0)+
  187. _endloop
  188.  
  189.     jmp    <loop
  190.  
  191.  
  192. ;****************************
  193. ;*     DATA - AREA        *
  194. ;****************************
  195.  
  196.     org    y:
  197.  
  198. count    ds    1
  199.  
  200.     endsec
  201.  
  202.     end
  203.